home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 11 - 1995 / 11.02 Feb 95 / Yenta / C Libraries / MemoryTools.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-04  |  1.4 KB  |  67 lines  |  [TEXT/KAHL]

  1. #include <MemoryTools.h>
  2.  
  3. /*------------------------------------------------------------------------------*/
  4.  
  5.     Ptr    Ptr2Ptr (Ptr InData)
  6.     /* make a copy of the passed pointer */
  7.     {
  8.         Ptr    NewPtr = NULL;
  9.         
  10.         if (InData)
  11.           {
  12.             NewPtr = NewPtrClear(GetPtrSize(InData));
  13.             if (NewPtr)
  14.               {
  15.                 BlockMove(InData, NewPtr, GetPtrSize(InData));
  16.                 return NewPtr;
  17.               }
  18.             else
  19.               return NULL;
  20.           }
  21.         else
  22.           return NULL;
  23.     }
  24.  
  25. /*------------------------------------------------------------------------------*/
  26.  
  27.     Handle    Ptr2Hand (Ptr Data)
  28.     /* create a handle containing the same data as the passed-in pointer */
  29.     {
  30.         Handle    TempHandle = NewHandle (GetPtrSize(Data));
  31.         
  32.         if (TempHandle)
  33.           BlockMove (Data, *TempHandle, GetPtrSize(Data));
  34.         return TempHandle;
  35.     }
  36.  
  37. /*------------------------------------------------------------------------------*/
  38.  
  39.     Ptr    Hand2Ptr (Handle Data)
  40.     /* create a ptr containing the same data as the passed-in handle */
  41.     {
  42.         Ptr    TempPtr = NewPtr (GetHandleSize(Data));
  43.         
  44.         if (TempPtr)
  45.           BlockMove (*Data, TempPtr, GetHandleSize(Data));
  46.         return TempPtr;
  47.     }
  48.  
  49. /*------------------------------------------------------------------------------*/
  50.  
  51.     void DoNukePtr (Ptr *PtrAddr)
  52.     {
  53.         if (*PtrAddr)
  54.           DisposPtr(*PtrAddr);
  55.         *PtrAddr = NULL;
  56.     }
  57.  
  58. /*------------------------------------------------------------------------------*/
  59.  
  60.     void DoNukeHandle (Handle *HandleAddr)
  61.     {
  62.         if (*HandleAddr)
  63.           DisposHandle(*HandleAddr);
  64.         *HandleAddr = NULL;
  65.     }
  66.  
  67.